package com.test.project_test.test.domain.service.impl;

import com.baomidou.mybatisplus.core.metadata.IPage;
import com.baomidou.mybatisplus.extension.plugins.pagination.Page;
import com.test.project_test.test.domain.PageDTO;
import com.test.project_test.test.domain.service.UserService;
import com.test.project_test.test.infrastructure.mybatis.UserMapper;
import com.test.project_test.test.infrastructure.mysql.po.User;
import org.springframework.stereotype.Service;

import javax.annotation.Resource;

/**
 * @author Duan SanMao
 * @date 2021/9/1
 */

@Service
public class UserServiceImpl implements UserService {

    @Resource
    private UserMapper userMapper;
    @Override
    public PageDTO<User> selectUserPage(Integer state) {

        // 不进行 count sql 优化，解决 MP 无法自动优化 SQL 问题，这时候你需要自己查询 count 部分
        // page.setOptimizeCountSql(false);
        // 当 total 为小于 0 或者设置 setSearchCount(false) 分页插件不会进行 count 查询
        // 要点!! 分页返回的对象与传入的对象是同一个
        Page<User> page = new Page<>(1, 2);

        IPage<User> iPage = userMapper.selectPageVo(page, state);

        return new PageDTO<User>(iPage.getRecords(),iPage.getTotal(),iPage.getPages(),iPage.getCurrent(),iPage.getSize());
    }
}
